package com.example.lock.乐观锁.cas;


public class TestVolatile extends Thread{

    volatile boolean flag = false;

    int i = 0;
    @Override
    public void run() {
        while(!flag){
            i++;
            //注意千万不要打印println
            // System.out.println("1111");
        }
    }

    public static void main(String[] args) throws Exception{
        TestVolatile testVolatile = new TestVolatile();
        testVolatile.start();
        Thread.sleep(2000);
        testVolatile.flag = true;
        System.out.println("stop:"+testVolatile.i);
    }
}
